/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
    
package be.vdabantwerpen.gow.services;
    
import be.vdabantwerpen.gow.dao.ActionDAO;
import be.vdabantwerpen.gow.dao.ActionDAOImpl;
import be.vdabantwerpen.gow.entities.Weight;
import be.vdabantwerpen.gow.entities.actions.Action;
import be.vdabantwerpen.gow.exceptions.ActionNotFoundException;
import be.vdabantwerpen.gow.exceptions.WeightNotFoundException;
import java.util.List;

/**
 *
 * @author tim.vandenlangenberg
 * @version 0.3
 */
public class ActionServiceImpl implements ActionService {
    private final ActionDAO actionDAO = new ActionDAOImpl();
    
    @Override
    public void create(Action action){
        actionDAO.create(action);
    }
    
    @Override
    public Action read(String className){
        Action action = actionDAO.read(className);
        if(action == null){
            throw new ActionNotFoundException();
        }
        return action;
    }
    
    @Override
    public void update(Action action){
        actionDAO.update(action);
    }
    
    @Override
    public void delete(Action action){
        actionDAO.delete(action);
    }
    
    @Override
    public List<Action> findAll(){
        List<Action> actions = actionDAO.findAll();
        if(actions == null || actions.isEmpty()){
            throw new ActionNotFoundException();
        }
        return actions;
    }
    
    @Override
    public List<Weight> findWeights(){
        List<Weight> weights = actionDAO.findWeights();
        if(weights == null || weights.isEmpty()){
            throw new WeightNotFoundException();
        }
        return weights;
    }
    
    @Override
    public Weight findWeight(String actionName){
        Weight weight = actionDAO.findWeight(actionName);
        if(weight == null){
            throw new WeightNotFoundException();
        }
        return weight;
    }
    
    @Override
    public void updateWeight(Weight weight){
        actionDAO.updateWeight(weight);
    }
    
}
